<template>
	<view class="fuyao-body">
		<view class="tn-padding-top content-bo" v-if="dataList.length">
			<view class="fuyao-item" v-for="(item, index) in dataList" :key="index">
				<view class="avatar-item tn-flex tn-flex-col-center tn-flex-row-center" @click="goDetail(item)">
					<tn-avatar v-if="item.childImgId" :src="item.childAvatar"></tn-avatar>
					<tn-avatar v-else src="https://img1.baidu.com/it/u=946811137,302769443&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1669309200&t=f41038b274ad95001481ff67599c99e2"></tn-avatar>
				</view>
				<view class="names-view" @click="goDetail(item)">
					<view class="erton-lv">
						{{item.childName}}的服药记录
					</view><view class="color-2 pn-text">
						{{item.parentName}}-{{item.relationshipStr}}
					</view>
				</view>
				<view class="times-view">
					<view class="tn-color-red tn-text-right erton-lv">
						{{item.stateStr}}
					</view><view class="color-2 pn-text">
						{{item.medicationTime}}
					</view>
				</view>
			</view>
		</view>
		
		<view class="fullhouse tn-flex tn-flex-row-center" v-else>
			<tn-empty mode="data"></tn-empty>
		</view>
		<!-- <view class="tn-padding-sm bottom-view">
				<tn-button width="100%" backgroundColor="#01BEFF" @click="addFunction">添加服药记录</tn-button>
		</view> -->
		<tn-toast
		  ref="toast"
		></tn-toast>
	</view>
</template>

<script>
	
	export default {
		name: 'youerruyuan',
		data(){
			return {
				showcalendar:false,
				dangqianriqi: '',
				dataList: [],
				pageIndex: 1,
				totalPage:0,
				imageTitle: '',
				childName: '',
			}
		},
		onPullDownRefresh() {
			this.pageIndex = 1
			this.getlist();
			console.log('下拉刷新------')
		},
		onReachBottom() {
			this.pageIndex++;
			this.getlist();
			console.log('上啦更多-------')
		},
		onShow() {
			this.getlist();
		},
		mounted() {
			let userInfo = uni.getStorageSync('userInfo');
			this.imageTitle = this.config.apiUri + '/sysFileInfo/previewImg?id=';
			
			
		},
		methods:{
			addFunction(){
				
				uni.navigateTo({
					url: '/pagesA/fuyao/dengji'
				})	
			},
			goDetail(item){
				  // uni.setStorageSync('yaopingDetail', item)
				  uni.navigateTo({
				  	url: `/pagesA/yuanwuduan/fuyaodetail?id=${item.id}`,
				  })
			},
			getlist(){
				if(this.totalPage > 0 && this.pageIndex > this.totalPage){
					this.$refs.toast.show({
					  title: '',
					  content: '没有更多了',
					  icon: '',
					  image: '',
					  duration: 1000
					})
					return;
				}
				let params = {
					PageNo: this.pageIndex,
					PageSize: 10
				}
				if(this.classId){
					params = {
						ClassId: this.classId,
						PageNo: this.pageIndex,
						PageSize: 10
					}
				}else{
					params = {
						PageNo: this.pageIndex,
						PageSize: 10
					}
				}
				this.request({
					url: '/MRegister/Page',
					method: 'get',
					params: params,
				}).then(res => {
					
						if(res.code == 200){
							if(this.pageIndex == 1){
								this.dataList = [];
							}
							let rows = res.data.rows;
							this.totalPage = res.data.totalPage;
							rows.forEach(item => {
								item.childAvatar = this.imageTitle + item.childImgId
								this.dataList.push(item);
							})
							uni.stopPullDownRefresh()
						}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.fuyao-body{
		min-height: 100vh;
		background-color: rgba(245, 245, 245, 1);
		.content-bo{
			padding:26rpx;
		}
	}
	.fuyao-item{
		width: 100%;
		height: 130rpx;
		padding: 20rpx;
		margin-bottom: 26rpx;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap:16rpx;
		background: #fff;
		border-radius: 16rpx;
	}
	.avatar-item{
		width:70rpx;
	}
	.names-view{
		flex:1
	}
	.times-view{
		width:240rpx
	}
	  .bottom-view{
		  position: fixed;
		  bottom: env(safe-area-inset-bottom);
		  width: 100%;
		  z-index: 11;
		  background-color: rgba(245, 245, 245, 1);
	  }
	.color-2{
		color: #555555;
	}
	.erton-lv{
		margin-bottom: 20rpx;
		font-size: 30rpx;
		font-weight: bold;
	}
	.pn-text{
		font-size: 24rpx;
	}
</style>